from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-05 07:57:16.052516
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 05, Aug, 2021
Time: 07:57:21
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.5080
Nobs: 373.000 HQIC: -46.0785
Log likelihood: 3990.33 FPE: 6.68721e-21
AIC: -46.4542 Det(Omega_mle): 5.27030e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.494357 0.096980 5.098 0.000
L1.Burgenland 0.100210 0.050258 1.994 0.046
L1.Kärnten -0.117672 0.024023 -4.898 0.000
L1.Niederösterreich 0.159868 0.106497 1.501 0.133
L1.Oberösterreich 0.081700 0.105206 0.777 0.437
L1.Salzburg 0.294467 0.051228 5.748 0.000
L1.Steiermark 0.008107 0.067917 0.119 0.905
L1.Tirol 0.142687 0.053755 2.654 0.008
L1.Vorarlberg -0.102307 0.048416 -2.113 0.035
L1.Wien -0.055648 0.093998 -0.592 0.554
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const -0.022331 0.234963 -0.095 0.924
L1.Burgenland -0.032370 0.121766 -0.266 0.790
L1.Kärnten 0.035540 0.058202 0.611 0.541
L1.Niederösterreich -0.223957 0.258021 -0.868 0.385
L1.Oberösterreich 0.551505 0.254894 2.164 0.030
L1.Salzburg 0.308263 0.124115 2.484 0.013
L1.Steiermark 0.110452 0.164551 0.671 0.502
L1.Tirol 0.309774 0.130238 2.379 0.017
L1.Vorarlberg -0.017857 0.117302 -0.152 0.879
L1.Wien -0.005789 0.227738 -0.025 0.980
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.261835 0.050295 5.206 0.000
L1.Burgenland 0.094842 0.026065 3.639 0.000
L1.Kärnten -0.005628 0.012459 -0.452 0.651
L1.Niederösterreich 0.226770 0.055231 4.106 0.000
L1.Oberösterreich 0.145404 0.054562 2.665 0.008
L1.Salzburg 0.040254 0.026568 1.515 0.130
L1.Steiermark 0.015917 0.035223 0.452 0.651
L1.Tirol 0.076681 0.027878 2.751 0.006
L1.Vorarlberg 0.057883 0.025109 2.305 0.021
L1.Wien 0.086508 0.048749 1.775 0.076
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198805 0.049236 4.038 0.000
L1.Burgenland 0.043841 0.025516 1.718 0.086
L1.Kärnten -0.004934 0.012196 -0.405 0.686
L1.Niederösterreich 0.129010 0.054068 2.386 0.017
L1.Oberösterreich 0.300385 0.053412 5.624 0.000
L1.Salzburg 0.099767 0.026008 3.836 0.000
L1.Steiermark 0.141827 0.034481 4.113 0.000
L1.Tirol 0.075456 0.027291 2.765 0.006
L1.Vorarlberg 0.056417 0.024580 2.295 0.022
L1.Wien -0.042277 0.047722 -0.886 0.376
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.204681 0.098775 2.072 0.038
L1.Burgenland -0.059038 0.051188 -1.153 0.249
L1.Kärnten -0.037869 0.024467 -1.548 0.122
L1.Niederösterreich 0.071132 0.108468 0.656 0.512
L1.Oberösterreich 0.190813 0.107153 1.781 0.075
L1.Salzburg 0.268005 0.052176 5.137 0.000
L1.Steiermark 0.083603 0.069174 1.209 0.227
L1.Tirol 0.127246 0.054750 2.324 0.020
L1.Vorarlberg 0.120434 0.049312 2.442 0.015
L1.Wien 0.035006 0.095737 0.366 0.715
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.034095 0.077587 0.439 0.660
L1.Burgenland 0.020459 0.040208 0.509 0.611
L1.Kärnten 0.052503 0.019219 2.732 0.006
L1.Niederösterreich 0.200018 0.085201 2.348 0.019
L1.Oberösterreich 0.343498 0.084168 4.081 0.000
L1.Salzburg 0.049448 0.040984 1.207 0.228
L1.Steiermark -0.005779 0.054336 -0.106 0.915
L1.Tirol 0.114851 0.043006 2.671 0.008
L1.Vorarlberg 0.066786 0.038734 1.724 0.085
L1.Wien 0.125717 0.075201 1.672 0.095
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.168347 0.093852 1.794 0.073
L1.Burgenland 0.038932 0.048637 0.800 0.423
L1.Kärnten -0.053971 0.023248 -2.322 0.020
L1.Niederösterreich -0.111110 0.103062 -1.078 0.281
L1.Oberösterreich 0.182261 0.101812 1.790 0.073
L1.Salzburg 0.028791 0.049576 0.581 0.561
L1.Steiermark 0.308080 0.065727 4.687 0.000
L1.Tirol 0.486419 0.052021 9.350 0.000
L1.Vorarlberg 0.071591 0.046854 1.528 0.127
L1.Wien -0.116631 0.090966 -1.282 0.200
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156119 0.102706 1.520 0.128
L1.Burgenland -0.004778 0.053225 -0.090 0.928
L1.Kärnten 0.064653 0.025441 2.541 0.011
L1.Niederösterreich 0.199852 0.112784 1.772 0.076
L1.Oberösterreich -0.127350 0.111417 -1.143 0.253
L1.Salzburg 0.247748 0.054252 4.567 0.000
L1.Steiermark 0.162313 0.071927 2.257 0.024
L1.Tirol 0.045123 0.056929 0.793 0.428
L1.Vorarlberg 0.120429 0.051274 2.349 0.019
L1.Wien 0.138735 0.099547 1.394 0.163
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.523826 0.055408 9.454 0.000
L1.Burgenland -0.024828 0.028714 -0.865 0.387
L1.Kärnten -0.009773 0.013725 -0.712 0.476
L1.Niederösterreich 0.191787 0.060845 3.152 0.002
L1.Oberösterreich 0.247279 0.060108 4.114 0.000
L1.Salzburg 0.022125 0.029268 0.756 0.450
L1.Steiermark -0.025448 0.038803 -0.656 0.512
L1.Tirol 0.075494 0.030712 2.458 0.014
L1.Vorarlberg 0.062092 0.027661 2.245 0.025
L1.Wien -0.060673 0.053704 -1.130 0.259
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.020541 0.065890 0.130685 0.112829 0.026930 0.064952 0.001196 0.169021
Kärnten 0.020541 1.000000 -0.060297 0.132476 0.044735 0.052092 0.446914 -0.092621 0.101292
Niederösterreich 0.065890 -0.060297 1.000000 0.284260 0.089274 0.277228 0.017785 0.143609 0.252330
Oberösterreich 0.130685 0.132476 0.284260 1.000000 0.172985 0.296398 0.168270 0.117418 0.126497
Salzburg 0.112829 0.044735 0.089274 0.172985 1.000000 0.124228 0.045311 0.103722 0.047868
Steiermark 0.026930 0.052092 0.277228 0.296398 0.124228 1.000000 0.126251 0.088450 -0.027948
Tirol 0.064952 0.446914 0.017785 0.168270 0.045311 0.126251 1.000000 0.036891 0.129893
Vorarlberg 0.001196 -0.092621 0.143609 0.117418 0.103722 0.088450 0.036891 1.000000 -0.047329
Wien 0.169021 0.101292 0.252330 0.126497 0.047868 -0.027948 0.129893 -0.047329 1.000000